﻿using System;
using System.Data;
using QLTH_DTO;

namespace QLTH_DATASSECC
{
  public class clsTCMDA : ConnectionData.clsKetNoi
  {
      String _sql;
      public DataTable DanhSachTCM()
      {
          _sql = "SELECT MATCM,TOCHUYENMON FROM TOCHUYENMON";
          return Load_DataTable(_sql);
      }

      public string Laymatcm(String _dk)
      {
          _sql = "SELECT MATCM FROM TOCHUYENMON WHERE TOCHUYENMON = N'"+_dk+"'";
          return laymadk(_sql).ToString();
      }

      public int ThemTCM(clsTCMDTO tcmdto)
      {
          int nameparam = 2;
          String[] name = new String[nameparam];
          Object[] values = new Object[nameparam];
          name[0] = "@Matcm"; values[0] = tcmdto.Matcm;
          name[1] = "@Tcm"; values[1] = tcmdto.Tentcm;
          _sql = "insert into TOCHUYENMON values(@Matcm, @Tcm)";
          return Nonquery(_sql, name, values, nameparam);
      }

      public int CapNhatTCM(clsTCMDTO tcmdto)
      {
          int nameparam = 2;
          String[] name = new String[nameparam];
          Object[] values = new Object[nameparam];
          name[0] = "@Matcm"; values[0] = tcmdto.Matcm;
          name[1] = "@Tcm"; values[1] = tcmdto.Tentcm;
          _sql = "UPDATE TOCHUYENMON SET TOCHUYENMON = @Tcm where MATCM = @Matcm";
          return Nonquery(_sql, name, values, nameparam);
      
      }

      public int XoaTCM(clsTCMDTO tcmdto)
      {
          int nameparam = 1;
          String[] name = new String[nameparam];
          Object[] values = new Object[nameparam];
          name[0] = "@Matcm"; values[0] = tcmdto.Matcm;
          _sql = "DELETE TOCHUYENMON WHERE MATCM=@Matcm";
          return Nonquery(_sql, name, values, nameparam);
      }

      public string macuoi()
      {
          _sql = "SELECT TOP 1 MATCM FROM TOCHUYENMON ORDER BY MATCM DESC";
          return laymacuoi(_sql);
      }
  }
}
